/*
 * @Date: 2025-06-13 10:50:10
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-09-27 23:38:14
 * @FilePath: \corpus\src\pages\resourceManagement\fileList\component\CreateKnowledge\index.tsx
 */
import { OPENENUM, SENSITIVEENUM } from '@/enum';
import { Form, Modal, Select } from 'antd';
import type React from 'react';
import { useEffect } from 'react';
import hooks from '../../hooks';

const EditAngent: React.FC = () => {
  const {
    setCreateKnowledgeVisible,

    addResourceFileKnowledgeContent,
    createKnowledgeVisible,
    formAnalysis,
    newList,
    getNewListContent,
    selectedRows,
  } = hooks.useContainer();
  const title = '生成知识库';

  const handleSubmit = () => {
    formAnalysis.validateFields().then((vals) => {
      const method = addResourceFileKnowledgeContent;
      method.run({
        ...vals,
        resourceFileIds: selectedRows.map((item) => item.id),
      });
    });
  };

  useEffect(() => {
    if (createKnowledgeVisible && selectedRows) {
      formAnalysis.setFieldValue('openProperty', selectedRows[0]?.openProperty);
      formAnalysis.setFieldValue('sensitiveLevel', selectedRows[0]?.sensitiveLevel);

      getNewListContent.run({
        openProperty: selectedRows[0]?.openProperty,
        current: 1,
        pageSize: 100,
      });
    } else {
      formAnalysis.resetFields();
    }
  }, [selectedRows, createKnowledgeVisible]);
  return (
    <Modal
      width={600}
      title={title}
      open={createKnowledgeVisible}
      onCancel={() => {
        formAnalysis.resetFields();
        setCreateKnowledgeVisible(false);
      }}
      onOk={handleSubmit}
      confirmLoading={addResourceFileKnowledgeContent?.loading}
    >
      <Form labelCol={{ span: 4 }} form={formAnalysis}>
        <Form.Item
          label={'选择知识库'}
          name="knowledgeId"
          rules={[{ required: true, message: '请选择' }]}
        >
          <Select
            style={{ width: '100% ' }}
            placeholder="请选择"
            fieldNames={{ label: 'name', value: 'id' }}
            options={newList}
          />
        </Form.Item>
        <Form.Item
          label={`公开属性`}
          name="openProperty"
          rules={[{ required: true, message: '请选择' }]}
        >
          <Select disabled placeholder="请选择">
            <Select.Option value={OPENENUM.PUBLICP}>无条件公开</Select.Option>
            <Select.Option value={OPENENUM.PROTECTED}>有条件公开</Select.Option>
            <Select.Option value={OPENENUM.PRIVATE}>不予公开</Select.Option>
            <Select.Option value={OPENENUM.DEPT}>部门公开</Select.Option>
          </Select>
        </Form.Item>
        <Form.Item
          label={`敏感等级`}
          name="sensitiveLevel"
          rules={[{ required: true, message: '请选择敏感等级' }]}
        >
          <Select disabled placeholder="请选择">
           <Select.Option value={SENSITIVEENUM.NO_SENSITIVE}>L1不敏感</Select.Option>
            <Select.Option value={SENSITIVEENUM.LOW_SENSITIVE}>L2低敏感</Select.Option>
            <Select.Option value={SENSITIVEENUM.LITTLE_SENSITIVE}>L3较敏感</Select.Option>
            <Select.Option value={SENSITIVEENUM.SENSITIVE}>L4敏感</Select.Option>
          </Select>
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default EditAngent;
